package com.example.pcapnative;

import com.sun.jna.ptr.PointerByReference;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
public class PcapTest {
    public void testPcap(HttpServletResponse resp) throws IOException{
        PointerByReference alldevsPP = new PointerByReference();
        PcapNativeMappings.PcapErrbuf errbuf = new PcapNativeMappings.PcapErrbuf();
        int rc = PcapNativeMappings.pcap_findalldevs(alldevsPP, errbuf);
        resp.getWriter().write("hello world from pcap");
    }
//    public static List<PcapNetworkInterface> findAllDevs() throws PcapNativeException {
//        PointerByReference alldevsPP = new PointerByReference();
//        NativeMappings.PcapErrbuf errbuf = new NativeMappings.PcapErrbuf();
//        List<PcapNetworkInterface> ifList = new ArrayList();
//        synchronized(lock) {
//            int rc = NativeMappings.pcap_findalldevs(alldevsPP, errbuf);
//            if (rc != 0) {
//                StringBuilder sb = new StringBuilder(50);
//                sb.append("Return code: ").append(rc).append(", Message: ").append(errbuf);
//                throw new PcapNativeException(sb.toString(), rc);
//            }
//
//            if (errbuf.length() != 0) {
//                logger.warn("{}", errbuf);
//            }
//
//            Pointer alldevsp = alldevsPP.getValue();
//            if (alldevsp == null) {
//                logger.info("No NIF was found.");
//                return Collections.emptyList();
//            }
//
//            NativeMappings.pcap_if pcapIf = new NativeMappings.pcap_if(alldevsp);
//
//            for(NativeMappings.pcap_if pif = pcapIf; pif != null; pif = pif.next) {
//                ifList.add(PcapNetworkInterface.newInstance(pif, true));
//            }
//
//            NativeMappings.pcap_freealldevs(pcapIf.getPointer());
//        }
//
//        logger.info("{} NIF(s) found.", ifList.size());
//        return ifList;
//    }
}